package com.gitee.feizns.quickstart.ding.talk.api.top.api.role;

import com.dingtalk.api.DefaultDingTalkClient;
import com.dingtalk.api.DingTalkClient;
import com.dingtalk.api.request.OapiRoleAddrolesforempsRequest;
import com.dingtalk.api.response.OapiRoleAddrolesforempsResponse;
import com.gitee.feizns.quickstart.ding.talk.utils.Utils;
import lombok.SneakyThrows;

/**
 * 批量增加员工角色（/topapi/role/addrolesforemps）
 * 接口路径：<a href="https://open.dingtalk.com/document/orgapp/add-role-information-to-employees-in-batches">批量增加员工角色（/topapi/role/addrolesforemps）</a>
 * @link <a href="https://open.dingtalk.com/document/orgapp/add-role-information-to-employees-in-batches">服务端API > 通讯录管理 > 角色管理 > 批量增加员工角色</a>
 * @author feizns
 * @since 2024/7/28
 */
public class AddRolesForEmps {

    /**
     * 执行
     * @param userIds 用户编号列表
     * @param roleIds 角色编号列表
     */
    @SneakyThrows
    public static String execute(String accessToken, String userIds, String roleIds) {
        DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/role/addrolesforemps");
        OapiRoleAddrolesforempsRequest req = new OapiRoleAddrolesforempsRequest();
        req.setRoleIds(roleIds);
        req.setUserIds(userIds);
        OapiRoleAddrolesforempsResponse rsp = client.execute(req, accessToken);
        return Utils.ifErrorThrow(rsp).getBody();
    }

}
